<?php

namespace App\Service\Home;

use App\Amqp\Producer\UpdateUserScoreProducer;
use App\Cache\RedisKey;
use App\Cache\UserScoreCache;
use App\Constants\RecommendedGradeCode;
use App\Helpers\RedisUtil;
use App\Model\UserProfile;
use App\Model\UserScore;
use App\Service\BaseService;
use App\Service\ServiceTrait\UpdateScoreTrait;
use Hyperf\Amqp\Producer;
use Hyperf\Utils\ApplicationContext;

class ResetScoreService extends BaseService
{
    use UpdateScoreTrait;
    public function handle()
    {
        $time = date("Y-m-d", strtotime('-'.RecommendedGradeCode::ACTIVE_DAY.' day'));

        $userIds = UserProfile::getRecentlyActiveUserIdByTime($time.' 00:00:00');
        UserScoreCache::delAllScore();

//        $userIds = UserProfile::getRecentlyActiveUserIdAll();

        foreach ($userIds as $one)
        {
            $message = new UpdateUserScoreProducer(['user_id' => $one]);
            $producer = ApplicationContext::getContainer()->get(Producer::class);
            $producer->produce($message);
        }

        $this->resetFixUserData();
    }
}